package org.bonorsoft.modules.control.service.impl;

import lombok.extern.slf4j.Slf4j;
import org.bonorsoft.common.constant.CacheConstant;
import org.bonorsoft.modules.control.mapper.CommonMapper;
import org.bonorsoft.modules.control.service.ICommonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
@Slf4j
public class CommonServiceImpl implements ICommonService {
    @Resource
    private CommonMapper commonMapper;

    @Override
    public int addPhoto(String id, String photo) {
        return commonMapper.addPhoto(id,photo);
    }

    @Override
    public String getPhoto(String id) {
        return commonMapper.getPhoto(id);
    }

    @Override
    public int updatePhoto(String id, String photo) {
        int count = commonMapper.count(id);
        if(count > 0) return commonMapper.updatePhoto(id, photo);
        else return commonMapper.addPhoto(id,photo);
    }

    @Override
    public void removeByIds(List<String> ids) {
        commonMapper.removeByIds(ids);
    }

    /**
     * 获取永安字典值
     * @return
     */
    @Override
    @Cacheable(value = CacheConstant.SYS_YONG_DICT_TABLE_CACHE)
    public String queryValueByParam(String value, String type) {
        log.info("永安系统-无缓存dictTable的时候调用这里！");
        return commonMapper.queryValueByParam(value, type);
    }

    /**
     * 获取永安字典值
     * @param table
     * @param text
     * @param code
     * @param key
     * @param param
     * @return
     */
    @Override
    @Cacheable(value = CacheConstant.SYS_YONG_TABLE_CACHE)
    public String queryCodeByParam(String table, String text, String code, String key, String param) {
        log.info("永安系统-无缓存dictTable的时候调用这里！");
        return commonMapper.queryCodeByParam(table,text,code,key,param);
    }
}
